﻿using System.Collections;
using System.Collections.Generic;
using System.Net.Sockets;
using UnityEngine;

public class TCPClient {
    private TcpClient tcpClient = new TcpClient();

    private static TCPClient instance = new TCPClient();
    public static TCPClient Instance { get { return instance; } }

    public void Connect()
    {
        tcpClient.Connect("10.15.130.247", 2569);
    }

    public void SendMsg(byte[] buffer)
    {
        tcpClient.GetStream().Write(buffer, 0, buffer.Length);
    }

    public byte[] RecvMsg()
    {
        if (!tcpClient.Connected || tcpClient.Available <= 0) return null;
        byte[] buffer = new byte[tcpClient.Available];
        tcpClient.GetStream().Read(buffer, 0, tcpClient.Available);
        return buffer;
    }

    public void DisConnect()
    {
        tcpClient.GetStream().Close();
    }

    public void Close()
    {
        tcpClient.Close();
    }
}
